/**
 * @file sideBarStore
 * @author wangshaozhi(wangshaozhi@baidu.com)
 */

import {action, makeObservable, observable} from "mobx";

export class SideBarStore {
    /** 当前点击的菜单项 */
    currSelectedKeys: string[] = ['index'];
    /** 当前展开的菜单项 */
    currOpenKeys: string[] = ['index'];

    constructor() {
        makeObservable(this, {
            currSelectedKeys: observable,
            currOpenKeys: observable
        });
    };

    update = action((data: Partial<SideBarStore>) => {
        Object.assign(this, data);
    });

    initSelectKeys = action((pathname: string) => {
        const pathList: string[] = pathname.slice(1).split('/');
        const reversedPathList: string[] = pathList.reverse();
        this.currSelectedKeys = reversedPathList;
        this.currOpenKeys = reversedPathList;
    });
}